/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2023-12-07 09:26:03
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-02-21 18:09:09
 * @FilePath: /yt-devops/lib/components/yt_form_text.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:flutter/material.dart';
import 'package:yt_devops/styles/styles.dart';

class YtFormText extends StatefulWidget {
  final String? title;

  final TextStyle? titleStyle;

  final String? hint;

  final String? value;

  final void Function(String)? onChange;

  const YtFormText(
      {super.key,
      this.title,
      this.titleStyle,
      this.value,
      this.hint,
      this.onChange});

  @override
  State<YtFormText> createState() => _YtFormTextState();
}

class _YtFormTextState extends State<YtFormText> {
  TextStyle titleTextStyle = TextStyles.lf14;

  TextStyle contentTextStyle = TextStyles.f14;

  final TextEditingController controller = TextEditingController();

  @override
  void didUpdateWidget(covariant YtFormText oldWidget) {
    if (oldWidget.value != widget.value) {
      controller.text = widget.value ?? '';
    }
    super.didUpdateWidget(oldWidget);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 50,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            widget.title ?? '',
            style: widget.titleStyle ?? titleTextStyle,
          ),
          Expanded(
              child: Text(
            widget.value ?? '',
            style: contentTextStyle,
            overflow: TextOverflow.ellipsis,
            textAlign: TextAlign.right,
          ))
        ],
      ),
    );
  }
}
